package com.ftg.learn.firstboot.dept.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ftg.learn.firstboot.dept.entity.Dept;
import com.ftg.learn.firstboot.dept.mapper.DeptMapper;
import com.ftg.learn.firstboot.dept.service.DeptService;
import com.ftg.learn.firstboot.util.ResultType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 一套dept的Restful api 包含swagger沙箱
 * @author KangJx
 * @date 2020/12/3
 */
@Api(value = "部门信息维护",description = "部门信息维护 Restful api")
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    DeptService deptService;

    @ApiOperation(value = "查看所有部门信息")
    @GetMapping("/all")
    public List<Dept> hellw(){
        return deptService.showall();
    }


    @ApiOperation(value="layui返回信息")
    @GetMapping("/layuipage")
    public ResultType<Dept> showpage(int page,int limit){
        return deptService.showpage(page,limit);
    }

    @ApiOperation(value="mybatis plus 原带分页信息")
    @GetMapping("/pluspage")
    public IPage<Dept> page2(int page,int limit){
        return deptService.showAllWithIpage(page,limit);
    }

    @PostMapping("/save")
    @ApiOperation("部门添加功能实现")
    public int saveDept(@RequestBody Dept d){
        return deptService.saveDept(d);
    }

    @PostMapping("/modify")
    @ApiOperation("部门修改功能实现")
    public int updateDept(@RequestBody Dept d){
        return deptService.updateDept(d);
    }

    @PostMapping("/modForEntry")
    @ApiOperation("部门修改功能实现,可以带复杂where条件,大于id")
    public int modForEntry(@RequestBody Dept d,@RequestParam String id){
        return deptService.modifyWithId(d,id);
    }

    @DeleteMapping("/del/{deptno}")
    @ApiOperation("部门删除功能实现")
    public int delDept(@PathVariable String deptno){
        return deptService.delDept(deptno);
    }

    @DeleteMapping("/delids/{ids}")
    @ApiOperation("部门多删除功能实现")
    public int delDept(@PathVariable List<Integer> ids){
        return deptService.delIds(ids);
    }

    @ApiOperation("用于主键查一操作")
    @PutMapping("/get/{deptno}")
    public Dept getOne(@PathVariable String deptno){
        return deptService.getOne(deptno);
    }

    @ApiOperation("用于多内容查一操作")
    @GetMapping("/geteq")
    public Dept getEq(@RequestParam String dname,@RequestParam String loc){
        return deptService.getOneWithWrapper(dname,loc);
    }
}
